import { Button, ButtonVariants, Modal, Title } from '@/shared/ui';
import { useWindowSize } from 'usehooks-ts';

import cs from './SendReview.module.scss';

export const SendReview = ({
  isOpen,
  handleClose,
  handleSend,
  handleSubmit,
  isBought,
  handleCancelWithoutRoute,
}: {
  isOpen: boolean;
  handleClose: () => void;
  handleSend: () => void;
  isBought?: boolean;
  handleSubmit?: () => void;
  handleCancelWithoutRoute: () => void;
}) => {
  const { width } = useWindowSize();
  const handleClick = () => {
    if (isBought) {
      handleSubmit && handleSubmit();
      handleClose();
    } else {
      handleSend();
    }
  };
  return (
    <Modal isOpen={isOpen} onCloseClick={handleCancelWithoutRoute} zIndex={1001}>
      <div className={cs.modal}>
        <Title size="l" tag="h3">
          Отправить отзыв?
        </Title>
        <div className={cs.content}>
          <Button className={cs.send} data-testid="button-send" onClick={handleClick} variant={ButtonVariants.Primary}>
            Отправить
          </Button>
          <Button className={cs.decline} data-testid="button-dont_send" onClick={handleClose}>
            Не отправлять
          </Button>
        </div>
      </div>
    </Modal>
  );
};
